<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	
    <style type="text/css">
		body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	</style>
	
    <script src="/js/jquery-1.8.2.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=25cc9404b6bb8d97da87d92a10e7f80d"></script>
	<title>中通物流周边网点</title>
</head>

<script type="text/javascript">
	var myobj;
	$(document).ready(function () {
		LX_val=parseFloat(getUrlParam('LX'));
		LY_val=parseFloat(getUrlParam('LY'));
		
		// alert(LX_val+LY_val);
		// url="/getstoreinfo/?LX="+LX_val+"&LY="+LY_val;
		// alert(url);
		
		var map = new BMap.Map("allmap");
		var point = new BMap.Point(LX_val, LY_val);
		map.centerAndZoom(point, 13);
		
	    $.ajax({ 
			   type: "GET",    
			   async: false,       
			   url: "/getstoreinfo/",           
			   data: {LX:LX_val,LY:LY_val},      
			   timeout: 5000,       
			   success: function (result) {
			   		 if(result==0){
			   		 	alert("附近暂无门店");
			   		 }
			   		 // alert(result);
					 myobj=eval(result);
					 // alert(myobj);
			         // data=eval("("+result+")");
			         // alert(myobj.length);
			         for (var i = 0; i < myobj.length; i++) {		
			         		
				            // alert(myobj[i].fields.latitude, myobj[i].fields.longitude);	
				            var point = new BMap.Point(myobj[i].fields.latitude, myobj[i].fields.longitude);	 //POI点坐标
				            var marker = new BMap.Marker(point);
				            var iw = createInfoWindow(i);	
				            
				            map.addOverlay(marker);
// 							
				            (function () {
				              var index = i;
				              var _iw = createInfoWindow(i);
				              var _marker = marker;
				              _marker.addEventListener("click", function () {
				                this.openInfoWindow(_iw);
				                
				              });
				              // // _iw.addEventListener("open", function () {						   
				                // // _marker.setIcon(myIconHover);
				              // // });
				              // // _iw.addEventListener("close", function () {
				                // // _marker.setIcon(myIcon);
				              // // });
				       		})();
				          }		
			   },       
			   error: function (jqXHR, textStatus, errorThrown) {
			   			alert(textStatus);
			   		}   
			   });
	// // 百度地图API功能
	});
	
	    //对应不同的Marker创建不同的InfoWindow
    function createInfoWindow(i) {
      var sContent ="<h4 style='margin:0 0 5px 0;padding:0.2em 0'>"+myobj[i].fields.store_name+"</h4>" + 
					"<img style='float:right;margin:4px' id='imgDemo' src='/media/img/"+myobj[i].fields.pic+"' width='139' height='104' />" + 
					"<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>门店地址："+myobj[i].fields.adress+"</p>" +
					"<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>联系电话："+myobj[i].fields.phone+"</p>" +
					"<a href='/ditupath/?slx="+LX_val+"&sly="+LY_val+"&tlx="+myobj[i].fields.latitude+"&tly="+myobj[i].fields.longitude+"'>去这里</a>"+ 
					"</div>";
	  // alert(sContent);
      // var iw = new BMap.InfoWindow("");
      var infoWindow = new BMap.InfoWindow(sContent); 
      // iw.setTitle("<label style=\"font-size: 16px;font-weight: bold;color: #CD533F;font-family: 'microsoft yahei';\">" + scenicSpots[i].Name + "</label>");
      // iw.setContent(sContent);
      return infoWindow;
    }
	function getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    		var r = window.location.search.substr(1).match(reg); 
    		if (r != null) return unescape(r[2]); return null;
    }
</script>

<body>
	<div id="allmap"> </div>
</body>
</html>